//! Shell step implementation

use crate::error::Result;
use crate::models::{
    config::StepConfig,
    step::{IStep, StepType, StepResult, StepContext},
};
use async_trait::async_trait;
use uuid::Uuid;

#[derive(Debug, Clone)]
pub struct ShellStep {
    id: Uuid,
    config: StepConfig,
}

impl ShellStep {
    pub fn new(config: StepConfig) -> Self {
        Self { id: Uuid::new_v4(), config }
    }
}

#[async_trait]
impl IStep for ShellStep {
    fn name(&self) -> &str { &self.config.step_name }
    fn step_type(&self) -> StepType { StepType::Shell }
    fn config(&self) -> &StepConfig { &self.config }
    fn config_mut(&mut self) -> &mut StepConfig { &mut self.config }
    async fn execute(&self, context: &mut StepContext) -> Result<StepResult> {
        let step_result = StepResult::new(self.id, self.name().to_string(), self.step_type());
        Ok(step_result.failure("Shell step not yet implemented".to_string()))
    }
    fn id(&self) -> Uuid { self.id }
    fn clone_step(&self) -> Box<dyn IStep> { Box::new(self.clone()) }
}
